<?php defined('_JEXEC') or die; 
/**
 * @package pmapi
 * @copyright Copyright (c)2014 Enrico Fagnoni
 * @license GNU General Public License version 3, or later
 *
 * @since 1.0.0
 */

// shortcuts
$p = $this->product;

//format conversion
$modified_on    = ApiHelper::datetime($p->modified_on);
$validFrom      = ApiHelper::datetime($p->product_price_publish_down) ;
$validThrough   = ApiHelper::datetime($p->product_price_publish_up);

?>
<?=$this->getTurtlePrefixes()?> 
@prefix : <#> .

<?=$this->getDefaultMetadata()?>
<>  foaf:primaryTopic :offering ;
    void:inDataset <<?=UriHelper::mkResourceURI('products',null,'dataset')?>> ;
.

<<?=UriHelper::mkResourceURI('user',$p->vendorUserId)?>> gr:offers :offering .

:offering a gr:Offering ;
    prov:generatedAtTime "<?=$modified_on?>"^^xsd:dateTime ;
    gr:validFrom "<?=$validFrom?>"^^xsd:dateTime ;
    gr:validThrough "<?=$validThrough?>"^^xsd:dateTime ;
<?php if (!empty($p->shopper_groups)):?>
    gr:eligibleCustomerTypes o:shoppergroup_<?=implode(' o:shoppergroup_', $p->shopper_groups)?> ;
<?php endif?>  
    gr:hasPriceSpecification :basePrice, :price, :srp ;
    gr:includes :item ;
.


<?php foreach ($this->show_prices as $price): ?>
:<?=$price->name?> a gr:UnitPriceSpecification ;
<?php if($price->type):?>
    gr:priceType "<?=$price->type?>" ; 
<?php endif?>
    gr:hasCurrency "<?=$price->currency?>" ;
    gr:hasCurrencyValue "<?=$price->value?>"^^xsd:floaf ;
    gr:valueAddedTaxIncluded <?=$price->taxIncluded?> ;
    gr:hasUnitOfMeasurement "C62" ;
.
<?php endforeach?>

:item a gr:ProductOrService ;
    gr:hasStockKeepingUnit "<?=$p->product_sku?>" ;
    gr:hasInventoryLevel :inventoryLevel;
    gr:hasMakeAndModel :model ;
<?php foreach ($p->categories as $category): ?>
    dcterms:subject o:productCategory_<?=$category?>;
<?php endforeach?>
.


:inventoryLevel: a gr:QuantitativeValue ;
    gr:hasValue <?=$p->product_in_stock?> ;
    gr:hasUnitOfMeasurement "C62" ;
.

:model a gr:ProductOrServiceModel ;
    gr:name "<?=$p->product_name?>" ;
    gr:description <?=ApiHelper::_T($p->product_s_desc)?> ;
    gr:hasManufacturer <<?=UriHelper::mkResourceURI('manufacturer',$p->virtuemart_manufacturer_id)?>> ;
.

<?php if($p->product_desc):?>
:model pm:hasRichDescription :richDescription .
:richDescription a pm:RichDescription ;
    dcterms:format "text/html" ;
    pm:hasRichDescriptionValue <?=ApiHelper::_T($p->product_desc)?> ;
.
<?php endif ?>

<?php if ($p->product_weight > EPSILON): ?>
:model gr:weight :weight .
:weight a gr:QuantitativeValue;
    gr:hasValue <?=$p->product_weight?> ;
    gr:hasUnitOfMeasurement "<?=ApiHelper::iso2Unifact($p->product_weight_uom)?>" ;
.
<?php endif; ?>

<?php if ($p->product_length > EPSILON): ?>
:model gr:depth :depth .
:depth a gr:QuantitativeValue;
    gr:hasValue <?=$p->product_length?> ;
    gr:hasUnitOfMeasurement "<?=ApiHelper::iso2Unifact($p->product_lwh_uom)?>" ;
.
<?php endif; ?>

<?php if ($p->product_width > EPSILON): ?>
:model gr:width :width .
:width a gr:QuantitativeValue;
    gr:hasValue <?=$p->product_width?> ;
    gr:hasUnitOfMeasurement "<?=ApiHelper::iso2Unifact($p->product_lwh_uom)?>" ;
.
<?php endif; ?>

<?php if ($p->product_height > EPSILON): ?>
:model gr:height :height .
:width a gr:QuantitativeValue;
    gr:hasValue <?=$p->product_height?> ;
    gr:hasUnitOfMeasurement "<?=ApiHelper::iso2Unifact($p->product_lwh_uom)?>" ;
.
<?php endif; ?>

<?php foreach( $this->show_images as $image):?>
:model <?=$this->getDepictionMetadata($image)?> .
<?php endforeach ?>

#########################################################
# Data extracted from textual descriptions:
#########################################################
<?php foreach( $this->extractedEmbeddedData as $source=>$turtle): ?>
    
# from <?=$source?>: 
<?=$turtle?> .
<?php endforeach?>

<?php 
if(JDEBUG){
    echo "#------------------ START DEBUGGING INFO -------------------------\n#";
    //print_r($this);
    echo preg_replace("/\n/", "\n#", ApiHelper::debugInfo($p));
    echo "\n#------------------ END DEBUGGING INFO -------------------------\n";
}
?>
